﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CIIS.Common
{
    public class NumberUtils
    {
        public static readonly NumberUtils Instance = new NumberUtils();
        NumberUtils() { }

        /// <summary>
        /// 返回指定的转换数字，不能成功转换则返回valueIfInvalid定义的值
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="valueIfInvalid"></param>
        /// <returns></returns>
        public int GetNumberFromObj(object obj, int valueIfInvalid)
        {
            if (obj != null)
            {
                int temp;
                if (int.TryParse(obj.ToString(), out temp))
                {
                    return temp;
                }
            }

            return valueIfInvalid;
        }
    }
}
